{%insert header.tpl%}
<script type="text/javascript" src="{% $THEME_URL %}/js/tiny_mce/jquery.tinymce.js"></script>
<link type="text/css" href="{% $THEME_URL %}/templates/integral/integral.css" rel="stylesheet" />
{%insert top.tpl%}
{%insert breadcrumbs.tpl%}
<script language="javascript" type="text/javascript">
	function show_tab(tab){
		var t = $(tab);
		t.parent().next().children().hide();
		$("#"+tab.id.replace("_tab","")+"_pane").show();
		t.parent().children().removeClass("active");
		t.addClass("active");
		$.cookie("<?php echo $this->PAGE->Name(); ?>_"+t.parent().attr("id"),t.attr("id"));
	}

	$(document).one("ready",function(){
		var tabs = $("div.tabs");
		var cv;
		for (var i = 0; i < tabs.length; i++){
			cv = $.cookie("<?php echo $this->PAGE->Name(); ?>_"+tabs[i].id);
			if (cv)
				show_tab($("#"+cv)[0]);
		}	
	});
</script>
<div id="main_tabs" class="tabs">
<span id="product_tab" class="tab active" onclick="javascript:show_tab(this);">Товар</span>
<?php if ($this->CurrentContext()->Product->ItemId()): ?>
<span id="images_tab" class="tab" onclick="javascript:show_tab(this);">Изображения</span>
<span id="yandex_tab" class="tab" onclick="javascript:show_tab(this);">Yandex Direct</span>
<?php endif; ?>
</div>
<div class="panes">
<div class="pane" id="product_pane">
<form class="editor" method="post">
	<input type="hidden" name="method" value="Save" />
	<div class="btn-holder"><button type="submit">Сохранить</button></div>
{%with Product%}
	<div><span class="label">Наименование</span><input class="property-value" type="text" name="product[Name]" value="{@% q < Name %}" /></div>
	<div>
		<span class="label">Категория учета</span>
		<select class="property-value" name="product[Category]">
		<?php
			foreach ($this->CurrentContext()->Property('Category')->Selection() as $key=>$value){
				echo '<option value="'.$key.'"'.(($key == $this->CurrentContext()->Property('Category')->Value())?' selected':'').'>'.$value.'</option>';
			}
		?>
		</select>
	</div>
	<div><span class="label">Цена</span><input class="property-value" type="text" name="product[Price]" value="{% Price %}" /></div>
	<div><span class="label">Количество</span><input class="property-value" type="text" name="product[Quantaty]" value="{% Quantaty %}" /></div>
	<div><span class="label">Зарезервировано</span>{% Reserved %}</div>
	<div>
		<span class="label">Статус отсутсвия на складе</span>
		<select class="property-value" name="product[UnavailableState]">
			<option value="">{% i < `none` %}</option>
		<?php
			foreach ($this->CurrentContext()->Property('UnavailableState')->Selection() as $key=>$value){
				echo '<option value="'.$key.'"'.(($key == $this->CurrentContext()->Property('UnavailableState')->Value())?' selected':'').'>'.$value.'</option>';
			}
		?>
		</select>
	</div>
{%endwith%}
	<table class="page-section">
	<tr>
	<td>
{%with ProductPage%}
	<div class="page-info">
	<div><span class="label">Заголовок страницы</span><input class="property-value" type="text" name="productpage[Title]" value="{@% q < Title %}" /></div>
	<div>
	<div id="page_texts" class="tabs">
	<span id="short_desc_tab" class="tab active" onclick="javascript:show_tab(this);">Краткое описание</span>
	<span id="long_desc_tab" class="tab" onclick="javascript:show_tab(this);">Описание</span>
	</div>
	<div class="panes">
		<div class="pane" id="short_desc_pane"><textarea class="wysiwyg property-value" type="text" name="productpage[Snippet]">{% q < Snippet %}</textarea></div>
		<div class="pane" id="long_desc_pane" style="display:none;"><textarea class="wysiwyg property-value" type="text" name="productpage[PageContents]">{% q < PageContents %}</textarea></div>
	</div>
	</div>
	<div><span class="label">Имя для ссылок</span><input class="property-value" type="text" name="productpage[Slug]" value="{% q < Slug %}" /></div>
	<div>
		<span class="label">Ссылка на страницу витрины</span>
		<a id="frontend-link"></a>
	</div>
	<div><span class="label">Мета-описание</span><textarea class="property-value" type="text" name="productpage[Description]">{% q < Description %}</textarea></div>
	<div><span class="label">Ключевые слова</span><textarea class="property-value" name="productpage[Keywords]">{% q < Keywords %}</textarea></div>
	<div><span class="label">Опубликован</span><input class="property-value" type="checkbox" name="productpage[IsPublished]"{%if IsPublished%} checked{%endif%} /></div>
	</div>
{%endwith%}
	</td>
	<td>
	<span class="label">Категории:</span>
	<div class="page-categories">
	{%iterate Categories as cat%}
	{%insert integral/integral.category_node.tpl%}
	{%iterate%}
	</div>
	</td>
	</tr>
	</table>
	<div class="btn-holder"><button type="submit">Сохранить</button></div>
</form>
</div>
<?php if ($this->CurrentContext()->Product->ItemId()): ?>
<div class="pane" id="images_pane" style="display:none;">
<script type="text/javascript" language="javascript">
	function add_img_fld(){
		$("#img_add_area").append('<div><input class="add_img_fld" name="addimages['+$("input.add_img_fld").length+']" type="file"/><a href="#" onclick="javascript:add_img_fld(this);return false;">еще...</a></div>');
	}
</script>
{%with Product%}
<form class="editor" method="post" enctype="multipart/form-data">
<input type="hidden" name="method" value="EditImages" />
<fieldset id="img_add_area">
<legend>Добавить изображения</legend>
<div><input class="add_img_fld" name="addimages[0]" type="file"/><a href="#" onclick="javascript:add_img_fld(this);return false;">еще...</a></div>
</fieldset>
<table id="imgs">
{%iterate Images as im%}
<tr>
	<td>
		{%with TinyThumbnail%}
		<a class="imageloader" href="{% q < GetLink %}"><img src="{% q < GetThumbnailLink %}" height="40" /></a>
		{%endwith%}
	</td>
	<td><textarea name="imagesdesc[{% ItemId %}]">{% q < Description %}</textarea></td>
	<td><input type="text" name="imagesorder[{% ItemId %}]" value="{% OrderNumber %}" /></td>
	<td><input type="checkbox" name="deleteimages[{% ItemId %}]" />Удалить</td>
</tr>
{%iterate%}
</table>
<div class="btn-holder"><button type="submit">{% i < `Save` %}</button></div>
</form>
{%endwith%}
</div>
<div class="pane" id="yandex_pane" style="display:none;">
{%if NeedsToken%}
Для получения доступа к Yandex Direct из магазина пройдите по <a target="_blank" href="{% q < TokenRequestUrl %}">ссылке</a>, и после авторизации обновите эту страницу.
{%else%}
{%if YandexItem%}
{%with YandexItem%}
<form method="post" class="editor">
	<input type="hidden" name="method" value="YandexDirectApply" />
	<div>
		<span class="label">Кампания</span>
		{%assign p Property < `Campaign`%}
		{%with p%}
			{%assign _v_ Value %}
			<select class="property-value" name="Campaign" value="{@% q < Campaign %}">
			{%iterate Selection as key > nm %}
			<option value="{% key %}"{%if _v_ key%} selected{%endif%}>{% nm %}</option>
			{%iterate%}
			</select>
		{%endwith%}
	</div>
	<div><span class="label">Заголовок</span><span></span><input class="property-value length-control" type="text" name="Title" value="{@% q < Title %}" /></div>
	<div><span class="label">Описание</span><span></span><textarea class="property-value length-control" type="text" name="Text">{% q < Text %}</textarea></div>
	<div><span class="label">Минус-слова</span><textarea class="property-value" name="MinusKeywords">{% q < MinusKeywords %}</textarea></div>
	<script language="javascript">
		$(document).ready(function(){
			var lc = $(".length-control");
			lc.each(function(){
				$(this).prev().text("("+$(this).val().length+")");
			});
			lc.keyup(function(){$(this).prev().text("("+$(this).val().length+")")});
		});1
	</script>
	<fieldset id="phrases">
		<legend>Фразы</legend>
		<script language="javascript">
			var phrase_id_counter = {% NextNewPhraseId %};
			function add_yandex_phrase(){
				$("#phrases").append("<div id=\"ph_{% ItemId %}_"+phrase_id_counter+"\"><input type=\"text\" name=\"PhraseList[{% ItemId %}_"+phrase_id_counter+"]\" value=\"\" /><a href=\"#\" onclick=\"javascript:del_yandex_phrase(&quot;{% ItemId %}_"+phrase_id_counter+"&quot;);return false;\">{% i < `Delete` %}</a></div>");
				phrase_id_counter++;
			}
			function del_yandex_phrase(id){
				$("#ph_"+id).remove();
			}
		</script>
		<a href="#" onclick="javascript:add_yandex_phrase();return false;">{% i < `Add`%}</a>
		{%iterate PhraseList as phrase_id > phrase %}
		<div id="ph_{% phrase_id %}">
		<input type="text" name="PhraseList[{% phrase_id %}]" value="{% q < phrase%}" />
		<a href="#" onclick="javascript:del_yandex_phrase(&quot;{% phrase_id %}&quot;);return false;">{% i < `Delete` %}</a>
		</div>
		{%iterate%}
	</fieldset>
<?php 
	$p = $this->CurrentContext()->Property('Stage');
	$this->_global_vars_['_stage_selection_'] = $p->Selection();
	$this->_global_vars_['_stage_value_'] = $p->Value(); 
?>
	<div>
		<span class="label">Стадия</span>
		<select class="property-value" name="Stage">
		{%iterate _stage_selection_ as stagecode > stagename%}
			<option value="{% stagecode %}" {%if stagecode _stage_value_%}selected="true"{%endif%}>{% stagename %}</option>
		{%iterate%}
		</select>
	</div>
	<div><span class="label">Кампания активна: {% CampaignStatusShow %}</span></div>		
	<div><span class="label">Объявление активно: {% IsActive %}</span></div>		
	<div><span class="label">Результат модерации: {% StatusBannerModerate %}</span></div>		
	<div class="btn-holder"><button type="submit">{% i < `Apply` %}</button></div>
</form>
{%endwith%}
{%else%}
<form method="post" />
	<input type="hidden" name="method" value="PublishToYandex" />
	<input type="submit" value="Create banner" />
</form>
{%endif%}
{%endif%}
</div>
<?php endif; ?>
</div>
<script language="javascript">
	$(document).ready(function(){
		$.getJSON("{@%FrontProductUrlQuery%}",function(data){
			$("#frontend-link").text(data).attr('href',data);
        });       				
		$("textarea.wysiwyg").tinymce({
				script_url : "{% $THEME_URL %}/js/tiny_mce/tiny_mce.js",
				mode : "textareas",
		        theme : "advanced",
		        plugins: "ccSimpleUploader,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		        theme_advanced_buttons3: "ccSimpleUploader,|,tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		        theme_advanced_toolbar_location : "top",
		        theme_advanced_toolbar_align : "left",
		        theme_advanced_statusbar_location : "bottom",
		 //       theme_advanced_resizing : true,
		        height: "600",
		        relative_urls : false,
		        file_browser_callback: "ccSimpleUploader",
		        plugin_ccSimpleUploader_upload_path: '../../../../../../files',                 
		        plugin_ccSimpleUploader_upload_substitute_path: '{% Root %}/files/'
		});
	});
</script>
{%insert footer.tpl%}
